#include "raftStub.h"

#include "myRpcChannel.h"
#include "myRpcController.h"
namespace raftStoreDataBase
{
    raftStub::raftStub( std::string ip, short port )
    {  // 这是设置stub的
        m_stub = new raftRpcProtoc::raftRpc_Stub( new RPC::MyrpcChannel( ip, port, true ) );
    }

    raftStub::~raftStub() { delete m_stub; }
    
    bool raftStub::AppendEntries( raftRpcProtoc::AppendEntriesArgs *args, raftRpcProtoc::AppendEntriesReply *response )
    {
        RPC::MyrpcController myController;
        m_stub->AppendEntries( &myController, args, response, nullptr );
        return !myController.Failed();
    }

    bool raftStub::RequestVote( raftRpcProtoc::RequestVoteArgs *args, raftRpcProtoc::RequestVoteReply *response )
    {
        RPC::MyrpcController myController;
        m_stub->RequestVote( &myController, args, response, nullptr );
        return !myController.Failed();
    }

    bool raftStub::InstallSnapshot( raftRpcProtoc::InstallSnapshotRequest *args, raftRpcProtoc::InstallSnapshotResponse *response )
    {
        RPC::MyrpcController myController;
        m_stub->InstallSnapshot( &myController, args, response, nullptr );
        return !myController.Failed();
    }

}  // namespace raftStoreDataBase